#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
const int MAXN2=1e6+5;
int t,o[25][3];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    for(int g=1;g<=t;g++){
        int n,m,l,vl,sum1=0,sum2=0;
        scanf("%d%d%d%d",&n,&m,&l,&vl);
        vector<int> p(MAXN2),D(n),V(n),A(n);
        vector<pair<int,int>> p2(MAXN2);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&D[i],&V[i],&A[i]);

        }
        for(int i=1;i<=n;i++){
            int temp;
            scanf("%d",&temp);
            p[temp]=1;
        }
        vector<vector<int>> f(MAXN);
        vector<int> bj(MAXN);
        for(int i=1;i<=n;i++){
            int d=D[i],v=V[i],a=A[i];
            int s,e;
            if(a<0 and v>vl){
                a=-a;
                int temp1=(v*v-vl*vl)/(2*a);
                double temp2=(v*v-vl*vl)/(2*a);
                s=d;
                if(temp1<temp2){
                    e=d+temp1;
                }
                else{
                    e=d+temp1-1;
                }
            }
            else if(a>0 and v<vl){
                s=d+(vl*vl-v*v)/(2*a)+1;
                e=l;
            }
            else if(a>=0 and v>vl){
                s=d;
                e=l;
            }
            else{
                s=-1;
                e=-2;
            }

            for(int j=s;j<=e;j++){
                if(p[j]==1){
                    f[i].emplace_back(j);
                }
            }


            if(f[i].size()>0){
                sum1++;
            }

            if(f[i].size()==1){
                p2[f[i][0]].first=2;
                sum2++;

            }
            else if(f[i].size()>1){
                int tag=0;
                for(int j=0;j<f[i].size();j++){
                    if(p2[f[i][j]].first==1){
                        p2[f[i][j]].first=2;
                        sum2++;
                        for(int k=j-1;k>=0;k--){
                            p2[f[i][k]].first=0;
                            p2[f[i][k]].second=0;
                        }
                        for(int k=0;k<f[p2[f[i][j]].second].size();k++){
                            p2[f[p2[f[i][j]].second][k]].first=0;
                            p2[f[p2[f[i][j]].second][k]].second=0;
                        }
                        bj[p2[f[i][j]].second]=0;

                        tag=1;
                        break;
                    }


                    /*if(p2[f[i][j]].first==2){
                        for(int k=j-1;k>=0;k--){
                            p2[f[i][k]].first=0;
                            p2[f[i][k]].second=0;
                        }
                        tag=1;
                        break;
                    }
                    */

                    p2[f[i][j]].first=1;
                    p2[f[i][j]].second=i;

                }
                if(tag==0){
                    bj[i]==1;
                }
            }

            for(int j=0;j<bj.size();j++){
                if(bj[j]==1){
                    sum2+=1;
                }
            }
        }
        o[g][0]=sum1;
        o[g][1]=m-sum2;
    }
    for(int i=1;i<=t;i++){
        printf("%d %d\n",o[i][0],o[i][1]);
    }
    return 0;
}


